<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .box {
        width: 100px;
        height: 100px;
        background-color: red;
        position: absolute;
        left: 50px;
        transition: all 1s;
      }
    </style>
  </head>
  <body>
    <div class="box"></div>

    <script>
      //点击box的时候 方块需要 从当前位置 + 300px的位置
      var boxEle = document.querySelector(".box");
      boxEle.onclick = function () {
        //获取box的当前left位置
        var leftNum = parseInt(getComputedStyle(this)["left"]);
        console.log(leftNum); //50PX
        var disNum = leftNum + 300;
        // 把box 的left值设置成disNum
        this.style.left = disNum + "px";
      };

      var str = "345345";
      console.log(Number(str)); //Number方法只能转换纯数字
      var str1 = "234234px";
      console.log(Number(str1)); //NaN
      console.log(Number(str1.slice(0, 6))); //这样截取方法也能获取数字但是很麻烦 如果数字很长不可能一个一个去数

      var str3 = "500px";
      console.log(parseInt(str3));
    </script>
  </body>
</html>
